package edu.xidian.bdilab.jrbigdata.controller.enterprise;

import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.domain.ProductRequest;
import edu.xidian.bdilab.jrbigdata.service.enterprise.productRequest.ProductRequestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.text.ParseException;

/**
 * @ClassName ProductRequestController
 * @Description TODO
 * @Author tuantuan
 * @Date 2019/4/2 上午11:05
 * @Version 1.0
 * @Attention Copyright (C), 2004-2019, BDILab, XiDian University
 **/
@CrossOrigin
@RestController
@Api(tags = {"ProductRequest-企业申请金融产品功能"})
public class ProductRequestController {
    @Autowired
    ProductRequestService productRequestService;
    ResponseResult responseResult = new ResponseResult();

    @PostMapping(value = "enterprise/productRequest/{productName}")
    public ResponseResult productRequest(@RequestParam String socialCode,
                                         @PathVariable(name = "productName")String productName,
                                         @RequestParam(required=false) String fundUsage){
        try {
            productRequestService.setRequestInfo(socialCode, productName,fundUsage);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        responseResult.setSuccess(true);
        responseResult.setCode(EnterpriseCode.PRODUCT_REQUEST_SUCCESS.getCode());
        responseResult.setMessage(EnterpriseCode.PRODUCT_REQUEST_SUCCESS.getMessage());
        return responseResult;
    }

    @ResponseBody
    @ApiOperation("查询所有企业申请金融产品")
    //@PostMapping(value = "enterprise/getAllProductRequest")
    @RequestMapping(value = "enterprise/getAllProductRequest", method = RequestMethod.POST)
    public ResponseResult getAllProductRequest(@RequestParam(defaultValue = "1")@ApiParam(value = "页码") int pageNum,
                                          @RequestParam(defaultValue = "10")@ApiParam(value = "每页记录数") int pageSize,
                                               @RequestParam(required = false) @ApiParam(value = "企业名称（支持模糊查询）") String enterpriseName,
                                               @RequestParam(required = false) @ApiParam(value = "企业代码（支持模糊查询）") String socialCode,
                                               @RequestParam(required = false) @ApiParam(value = "金融产品名称（支持模糊查询）") String productName,
                                               @RequestParam(required = false) @ApiParam(value = "银行名称（支持模糊查询）") String bankName,
                                               HttpSession httpSession) throws Exception{
        ResponseResult responseResult = productRequestService.getAllProductRequest(pageNum,pageSize,enterpriseName,socialCode,productName,bankName);
        return responseResult;
    }
}
